/**
 * Created by Alice on 2016/9/19 0019
 */

var _tempHtml = $('#_stream_div').clone();
$(function () {
    $('.fa-plus-square-o').click(function () {
        $('#_stream_form').after(_tempHtml.html());
        $('.fa-minus-square-o').click(function () {
            $(this).parent().remove();
        });
    });
    $("#sys_court_status").find("a").attr("href", r.base_path + "system_monitor/sys_court_status?courtUid=" + r.court_id);
    $("#sys_play_info").find("a").attr("href", r.base_path + "system_monitor/sys_play_info?court=Uid" + r.court_uid);
    $("#sys_fault_condition").find("a").attr("href", r.base_path + "views/system_monitor/sys_fault_condition.html?court=" + r.court_id);
    $("#sys_meeting").find("a").attr("href", r.base_path + "views/system_monitor/sys_meeting.html?court=" + r.court_id);
    $("#sys_server_status").find("a").attr("href", r.base_path + "system_monitor/sys_server_status?courtUid=" + r.court_uid);
    $("#sys_warning_message").find("a").attr("href", r.base_path + "system_monitor/sys_warning_message?courtUid=" + r.court_uid);
    $("#sys_log_info").find("a").attr("href", r.base_path + "system_monitor/sys_log_info?courtUid=" + r.court_uid);
    selectAllCourtRoom();
    initcollapseOne();
    initcollapseTwo();
    $("#loading").hide();
});

function initcollapseOne() {
    initCourtInfoModal();
    $("#add").click(function () {
        $("#_cid").val("");
        document.getElementById("form").reset();
        $('.temp-div').remove();
        $("#_editCourtInfo").modal("show");
    });
    $("#_search_courtinfo").click(function () {
        getSumNumberForCourtSetting();
    });
    $("#_export").click(function () {
        var courtname = $("#deviceCourtCourtList").find("option:selected").text();
        var form = document.getElementById("_form");
        // form.target="_blank";
        form.action = r.base_path + "sys/courtEquipment/exportCourtEquipment";
        var newElem = document.getElementById("fileTitle") ? document.getElementById("fileTitle") : document.createElement("input");
        newElem.setAttribute("name", "fileTitle");
        newElem.setAttribute("id", "fileTitle");
        newElem.setAttribute("type", "hidden");
        newElem.setAttribute("value", courtname);
        form.appendChild(newElem);
        form.submit();
        // $.get(basePath+"sys/courtEquipment/exportCourtEquipment", {courtId: courtId,courtName:$("#_search_eq").val()}, function (result) {
        //
        // });
        // layer.msg("开始导出！");
        // $.post(basePath+"sys/courtEquipment/exportCourtEquipment", {courtId: courtId,courtName:$("#_search_eq").val()}, function (result) {
        //
        // });
    })
}
function initcollapseTwo() {
    $("#add_courtequipment_btn").click(function () {
        $("#_uid").val("");
        document.getElementById("_form_eq").reset();
        $("#_editEqInfo").modal("show");
    });

    //法庭设备管理select的change事件
    $("#parentCourtList").change(function () {
        getSumNumberForCourtSetting();
        courtSumByCourtId();
    });
    //法庭设备管理select的change事件
    $("#deviceCourtCourtList").change(function () {
        getSumNumberForCourtEquipment();
    });

    $("#_court").change(function () {
        selectCourtRoom($("#_court").val());
    });
    $("#_search_eq").click(function () {
        getSumNumberForCourtEquipment();
    });
    getSumNumberForCourtEquipment();
}

/**
 *  列出法庭
 */
function selectAllCourtRoom() {
    $.ajax({
        url: r.base_path + "sys/courtSetting/selectCourtDispose",
        type: "post",
        data: {
            courtId: r.court_id,
            level: r.level
        },
        async: false,
        dataType: "json",
        success: function (result) {
            if (result.data) {
                $("#parentCourtList").empty();
                $("#deviceCourtCourtList").empty();
                $("#_court").empty();
                $.each(result.data, function (i, n) {
                    // $("#_parentCourtList_ul").append('<li role="presentation"><a role="menuitem" tabindex="-1" href="javascript:searchCourtInfo(\'' + n.courtid + '\',\'' + n.courtname + '\');">' + n.courtname + '</a></li>');
                    $("#parentCourtList").append("<option value='" + n.courtid + "'>" + n.courtname + "</option>");
                    $("#deviceCourtCourtList").append("<option value='" + n.courtid + "'>" + n.courtname + "</option>");
                    $("#_court").append("<option value='" + n.courtid + "'>" + n.courtname + "</option>");
                });
                // $("#parentCourtList").find("button").html(result.data[0].courtname + '<span class="caret"></span>');
                // $("#parentCourtList").find("input").val(result.data[0].courtid);
                getSumNumberForCourtSetting(result.data[0].courtid);
                selectCourtRoom(result.data[0].courtid);
            }
        }
    });
}

//_________________________________法庭设置

function initCourtInfoModal() {
    $.ajaxSetup({
        async: false
    });
    $.ajax({
        url: r.base_path + "sys/courtSetting/loadCourtRoomType",
        type: "post",
        async: false,
        dataType: "json",
        success: function (result) {
            var courtRoomTypeList = result.data;
            if (courtRoomTypeList != null) {
                $(".court_room_type").html("");
                for (var i = 0; i < courtRoomTypeList.length; i++) {
                    $(".court_room_type").append("<option>" + courtRoomTypeList[i] + "</option>");
                    // $(".court_room_type_update").append("<option>" + courtRoomTypeList[i] + "</option>");
                }
            }
        }
    });
    $.post(r.base_path + "device/selectDeviceType", {}, function (result) {
        if (result.data) {
            $(".devicetype").empty();
            $.each(result.data, function (i, valueOfElement) {
                $(".devicetype").append('<option value="' + i + '">' + valueOfElement + '</option>')
            });
        }
    }, 'json');
    $.post(r.base_path + "device/selectDeviceCompany", {}, function (result) {
        if (result.data) {
            $(".venderForStream").empty();
            $.each(result.data, function (i, valueOfElement) {
                $(".venderForStream").append('<option value="' + valueOfElement + '">' + valueOfElement + '</option>')
            });
            // $(".venderForStream").val(result.data[0]);
        }
    }, 'json');
}

/**
 * 获取总的法庭数量
 */
function courtSumByCourtId() {
    var _courtId = $("#parentCourtList").val();
    $.post(r.base_path + "sys/courtSetting/courtSumByCourtId", {courtId: _courtId}, function (result) {
        $("#sumNumber").val(result.data);
    });
}
function updateSumCounrtNumber() {
    var courtId = $("#parentCourtList").val();
    var sumNumber = $("#sumNumber").val();
    if (!isNaN(sumNumber)) {
        $.post(r.base_path + "sys/courtSetting/saveSumCourt", {courtid: courtId, num: sumNumber}, function (result) {
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.msg(result.msg);
            });

        });
    } else {
        layui.use('layer', function () {
            var layer = layui.layer;
            layer.msg("请输入数字！");
        });

    }
}

function temp(htmlid, id, value) {
    // console.log(id, value);
    $(htmlid).find("button").html(value + '<span class="caret"></span>');
    $(htmlid).find("input").val(id);
}

var pageSize = 10;

function getSumNumberForCourtSetting() {
    var courtId = $("#parentCourtList").val();
    var courtName = $("#search_court_input").val();
    $.ajax({
        url: r.base_path + "sys/courtSetting/countCourtByCourtId",
        type: "post",
        data: {
            courtId: courtId,
            courtName: courtName
        },
        dataType: "json",
        success: function (result) {
            // console.log(result);
            courtSumByCourtId(courtId);
            if (result.data == 0) {
                page(1, 1, null);
            } else {
                page(1, Math.ceil(result.data / pageSize), getCourtInfo);
            }
            getCourtInfo(1);
        },
        error: function () {
        }
    });
}
function getCourtInfo(page) {
    var courtName = $("#search_court_input").val();
    $.ajax({
        url: r.base_path + "sys/courtSetting/getCourtInfoByCourtId",
        type: "post",
        data: {
            courtId: r.court_id,
            page: page,
            pageSize: pageSize,
            courtName: courtName
        },
        dataType: "json",
        success: function (result) {
//             console.log(result);
            var courtList = result.data;
//            $("#courtSetting").find("tbody").html("");
//            if (courtList.length == 0) {
//                $("#courtSetting").find("tbody").html("<tr><td>暂无数据</td></tr>");
//            }

//          for (var i = 0; i < courtList.length; i++) {
//          var cid = courtList[i].cid;
//          var courtName = courtList[i].court_name;
//          var courtType = courtList[i].court_type;
//          var streamAddress = courtList[i].stream_address;
//          var parentCount = courtList[i].parent_count;
//          var definition = courtList[i].definition;
//          var vender = courtList[i].vender;
//          var streamAddressList = streamAddress.split(",");
//          var channel = streamAddressList[0].split("<=>")[0];
//          var stream = streamAddressList[0].split("<=>")[1];
//          var tr = '<tr>' +
//              '<td rowspan =' + streamAddressList.length + '>' + cid + '</td>' +
//              '<td rowspan =' + streamAddressList.length + '>' + courtName + '</td>' +
//              '<td rowspan =' + streamAddressList.length + '>' + courtType + '</td>' +
//              '<td>' + channel + '</td>' +
//              '<td>' + stream + '</td>' +
//              '<td rowspan =' + streamAddressList.length + '>' + definition + '</td>' +
//              '<td rowspan =' + streamAddressList.length + '>' + vender + '</td>' +
//              '<td rowspan =' + streamAddressList.length + '>' + parentCount + '</td>' +
//              '<td rowspan =' + streamAddressList.length + '>' + '<a href="javascript:getCourtSettingByUid(\'' + cid + '\')"><i class="fa fa-edit fa-lg"></i></a>&nbsp;<a href="javascript:deleteCourtInfo(\'' + cid + '\')" ><i class="fa fa-trash-o fa-lg"></i></a></td>' +
//              '</tr>';

//          $("#courtSetting").find("tbody").append(tr);
//          for (var k = 1; k < streamAddressList.length; k++) {
//              channel = streamAddressList[k].split("<=>")[0];
//              stream = streamAddressList[k].split("<=>")[1];
//              tr = '<tr>' +
//                  '<td>' + channel + '</td>' +
//                  '<td>' + stream + '</td>' +
//                  '</tr>';
//              $("#courtSetting").find("tbody").append(tr);
//          }
//      }

            $('#tableDivId1').empty();
            var tr = ' <table id="table1" class="table table-bordered text-center" ></table>';
            $('#tableDivId1').append(tr);
            for (var i = 0; i < courtList.length; i++) {
                //利用其中一个无用字段来显示其他需要展示的信息
//            	courtList[i].devicetype='<a href="javascript:getCourtSettingByUid(\'' + courtList[i].cid + '\')"><i class="fa fa-edit fa-lg"></i></a>&nbsp;<a href="javascript:deleteCourtInfo(\'' + courtList[i].cid + '\')" ><i class="fa fa-trash-o fa-lg"></i></a>'
                var streamAddress = courtList[i].stream_address;
                var streamAddressList = streamAddress.split(",");
                courtList[i].stream_address = streamAddressList[0].split("<=>")[0];
                courtList[i].activestatus = streamAddressList[0].split("<=>")[1];
            }
            $('#table1').bootstrapTable({
                columns: [{
                    field: 'cid',
                    title: '编号',
                    width: '5.3%',
                    formatter: function (value, row, index) {
                        return (index + 1) > 9 ? index + 1 : '0' + (index + 1);
                    }
                }, {
                    field: 'court_name',
                    title: '法庭名称'
                }, {
                    field: 'court_type',
                    title: '法庭类型'
                }, {
                    field: 'stream_address',
                    title: '通道名'
                }, {
                    field: 'activestatus', //利用别的字段来显示此信息
                    title: '直播流地址'
                }, {
                    field: 'definition',
                    title: '清晰度'
                }, {
                    field: 'vender',
                    title: '厂商'
                }, {
                    field: 'parent_count',
                    title: '所属法院'
                }, {
                    field: 'edit',
                    title: '操作',
                    class: 'center se_operation',
                    formatter: function (value, row) {
                        // console.log(row.uid);
                        var html = '<a href="javascript:getCourtSettingByUid(\'' + row.cid + '\')"><i class="fa fa-edit fa-lg"></i></a>&nbsp;<a href="javascript:deleteCourtInfo(\'' + row.cid + '\')" ><i class="fa fa-trash-o fa-lg"></i></a>'
                        // '<a href="javascript:deleteCourtequipment(\'' + index + '\')" ><i class="fa fa-trash-o fa-lg"></i></a>';
                        return html;
                    }
                }
                ],

                data: result.data
            })
//            $("#courtSetting").show();
        }
//        error: function () {
//        }

    });
}

function getCourtSettingByUid(cid) {
    $("#loading").show();
    $.ajax({
        url: r.base_path + "sys/courtSetting/getCourtSettingByCid",
        type: "post",
        data: {
            cid: cid
        },
        dataType: "json",
        success: function (result) {
            var data = result.data;
            // console.log(data);
            var courtName = data.court_name;
            var courtType = data.court_type;
            var streamIp = data.stream_address;
            var definition = data.definition;
            var vender = data.vender;
            var streamAddressList = streamIp.split(",");
            var channel = streamAddressList[0].split("<=>")[0];
            var stream = streamAddressList[0].split("<=>")[1];
            $(".courtNameForSetting").val(courtName);
            $(".court_room_type").val(courtType);
            $(".channelNameForStream").val(channel);
            $(".streamNameForStream").val(stream);
            $(".clearNameForSetting").val(definition);
            $(".venderForStream").val(vender);
            // $(".venderForStream option:contains('" + vender + "')").attr("selected", true);
            $(".avdevice").val(data.avdevice);
            $(".devicetype").val(data.devicetype);
            $(".activestatus").val(data.activestatus);
            $("#_cid").val(cid);
            $('.temp-div').remove();
            for (var int = 1; int < streamAddressList.length; int++) {
                channel = streamAddressList[int].split("<=>")[0];
                stream = streamAddressList[int].split("<=>")[1];
                var temp = _tempHtml.clone();
                temp.find('input').eq(0).attr("value", channel);
                temp.find('input').eq(1).attr("value", stream);
                $('#_stream_form').after(temp.html());
            }
            $('.fa-minus-square-o').click(function () {
                $(this).parent().remove();
            });
            $("#loading").hide();
            $('#_editCourtInfo').modal("show");
        },
        error: function () {
        }
    });
}

//修改法庭
function update_court_btn() {
    //获取法庭参数
    var courtName = $(".courtNameForSetting").val();
    var courtType = $(".court_room_type").val();
    var $channelNameList = $(".channelNameForStream");
    var $streamNameForStreamList = $(".streamNameForStream");
    var streamIp = "";
    for (var i = 0; i < $channelNameList.length; i++) {
        streamIp += $channelNameList.eq(i).val() + "<=>" + $streamNameForStreamList.eq(i).val() + ",";
    }
    streamIp = streamIp.substring(0, streamIp.length - 1);
    var definition = $(".clearNameForSetting").val();
    var vender = $(".venderForStream").val();
    var cid = $("#_cid").val();
    var parentCourt = $("#parentCourtList").find("option:selected").text();
    if (!parentCourt) {
        alert("法院不能为空！");
        return;
    }
    if (courtName == null || courtName == "") {
        alert("法庭名称不能为空");
        return;
    }
    if (courtType == null || courtType == "") {
        alert("法庭类型不能为空");
        return;
    }
    if (streamIp == null || streamIp == "") {
        alert("直播流地址不能为空");
        return;
    }
    if (definition == null || definition == "") {
        alert("清晰度不能为空");
        return;
    }
    if (vender == null || vender == "") {
        alert("厂商不能为空");
        return;
    }
    var _court_id = $("#parentCourtList").val();
    if (cid) {
        $.ajax({
            url: r.base_path + "sys/courtSetting/updateCourt",
            type: "post",
            dataType: "json",
            data: {
                cid: cid,
                court_name: courtName,
                court_type: courtType,
                stream_address: streamIp,
                parent_count: parentCourt,
                definition: definition,
                vender: vender,
                avdevice: $("#avdevice").val(),
                devicetype: $(".devicetype").val(),
                activestatus: $(".activestatus").val()
            },
            success: function (result) {
                layui.use('layer', function () {
                    var layer = layui.layer;
                    layer.msg("更新成功！");
                });
                getSumNumberForCourtSetting();
                $('#_editCourtInfo').modal("hide");
            },
            error: function () {
            }
        });
    } else {
        $.ajax({
            url: r.base_path + "sys/courtSetting/insertCourt",
            type: "post",
            dataType: "json",
            data: {
                court_id: _court_id,
                court_name: courtName,
                court_type: courtType,
                stream_address: streamIp,
                parent_count: parentCourt,
                definition: definition,
                vender: vender,
                avdevice: $("#avdevice").val(),
                devicetype: $(".devicetype").val(),
                activestatus: $(".activestatus").val()
            },
            success: function (result) {
                if (result.data != 0) {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg("添加成功！");
                    });
                    getSumNumberForCourtSetting();
                    $('#_editCourtInfo').modal("hide");
                }
            },
            error: function () {
            }
        });
    }


}

function deleteCourtInfo(cid) {
    $('#_deleteCourtInfo').find("input").val(cid);
    $('#_deleteCourtInfo').find(".modal-body").html("删除数据吗？");
    $('#_deleteCourtInfo').modal();
}
function deleteCourtInfoModal() {
    var val = $('#_deleteCourtInfo').find("input").val();
    $.ajax({
        url: r.base_path + "sys/courtSetting/deleteCourtByCid",
        type: "post",
        data: {
            cid: val
        },
        dataType: "json",
        success: function (result) {
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.msg("操作成功！");
            });
            getSumNumberForCourtSetting();
            $('#_deleteCourtInfo').modal('hide');
        },
        error: function () {
        }
    });
}

function page(now, totalPages, callback) {
    base.pagination('#_page', {
        currentPage: now,
        totalPages: totalPages,
        onPageClicked: function (page) {
            callback(page);
        }
    });
}

//_________________________________法庭设备管理
var emPageSize = 10;
function getSumNumberForCourtEquipment() {
    var courtId = $("#deviceCourtCourtList").val();
    var courtname = $("#search_courtequipment_input").val();
    $.ajax({
        url: r.base_path + "sys/courtEquipment/countCourtByCourtId",
        type: "post",
        data: {
            courtId: courtId,
            courtname: courtname
        },
        dataType: "json",
        success: function (result) {
            // console.log(result);
            if (result.data == 0) {
                pageEq(1, 1, null);
            } else {
                pageEq(1, Math.ceil(result.data / pageSize), getCourtEquipmentInfo);
            }
            getCourtEquipmentInfo(1, emPageSize);
        },
        error: function () {
        }
    });
}

function getCourtEquipmentInfo(emPage, emPageSize) {
    var courtId = $("#deviceCourtCourtList").val();
    var courtname = $("#search_courtequipment_input").val();
    if (!courtId) {
        alert("未选择法院！");
        return;
    }
    $.ajax({
        url: r.base_path + "sys/courtEquipment/getCourtEquipmentInfo",
        type: "post",
        dataType: "json",
        data: {
            courtId: courtId,
            emPage: emPage,
            emPageSize: emPageSize,
            courtname: courtname
        },
        success: function (result) {
//            $("#court_equipment_table").find("tbody").empty();
//            if (result.data.length == 0) {
//                $("#court_equipment_table").find("tbody").html("<tr><td>暂无数据</td></tr>");
//            }
            $('#tableDivId2').empty();
            var tr = ' <table id="table2" class="table table-bordered text-center" ></table>';
            $('#tableDivId2').append(tr);
//             for (var i = 0; i < result.data.length; i++) {
//            	 result.data[i].courtroomid= '<a href="javascript:selectCourtequipment(\'' +result.data[i].uid + '\')"><i class="fa fa-edit fa-lg"></i></a>&nbsp;<a href="javascript:deleteCourtequipment(\'' + result.data[i].uid + '\')" ><i class="fa fa-trash-o fa-lg"></i></a>'
//            	 
//			}
            $('#table2').bootstrapTable({
                columns: [{
                    field: 'uid',
                    title: '编号',
                    width: '5.3%',
                    formatter: function (value, row, index) {
                        return (index + 1) > 9 ? index + 1 : '0' + (index + 1);
                    }
                }, {
                    field: 'courtroomname',
                    title: '法庭名称'
                }, {
                    field: 'devno',
                    title: '设备编号'
                }, {
                    field: 'devname',
                    title: '设备名称'
                }, {
                    field: 'devtype',
                    title: '设备型号'
                }, {
                    field: 'devpos',
                    title: '设备位置'
                }, {
                    field: 'devstatus',
                    title: '设备状态'
                }, {
                    field: 'devmemo',
                    title: '说明'
                }, {
                    field: 'edit',
                    title: '操作',
                    class: 'center se_operation',
                    formatter: function (value, row) {
                        // console.log(row.uid);
                        var html = '<a href="javascript:selectCourtequipment(\'' + row.uid + '\')"><i class="fa fa-edit fa-lg"></i></a>&nbsp;<a href="javascript:deleteCourtequipment(\'' + row.uid + '\')" ><i class="fa fa-trash-o fa-lg"></i></a>'
                        return html;
                    }
                }
                ],

                data: result.data
            })
//            $.each(result.data, function (i, n) {
//                var status = "未知";
//                if (null != n.devstatus) {
//                    if (n.devstatus == "0") {
//                        status = "已损坏";
//                    } else if (n.devstatus == "1") {
//                        status = "设备正常";
//                    }
//                }
//                var tr = '<tr>' +
//                    '<td >' + n.uid + '</td>' +
//                    '<td >' + n.courtroomname + '</td>' +
//                    '<td >' + n.devno + '</td>' +
//                    '<td >' + n.devname + '</td>' +
//                    '<td >' + n.devtype + '</td>' +
//                    '<td >' + n.devpos + '</td>' +
//                    '<td >' + status + '</td>' +
//                    '<td >' + n.devmemo + '</td>' +
//                    '<td >' + '<a href="javascript:selectCourtequipment(\'' + n.uid + '\')"><i class="fa fa-edit fa-lg"></i></a>&nbsp;<a href="javascript:deleteCourtequipment(\'' + n.uid + '\')" ><i class="fa fa-trash-o fa-lg"></i></a></td>' +
//                    '</tr>';
//                $("#court_equipment_table").find("tbody").append(tr);
//            });
            $("#court_equipment_table").show();
        }
    });
}

function selectCourtRoom(courtId) {
    $.post(r.base_path + "sys/courtEquipment/selectCourtRoom", {courtId: courtId}, function (result) {
        if (result.data) {
            $("#_courtRoom").empty();
            $.each(result.data, function (i, n) {
                $("#_courtRoom").append("<option value='" + n.uid + "'>" + n.courtroomname + "</option>");
            });
        }
    }, 'json')
}

function selectCourtequipment(uid) {
    $.post(r.base_path + "sys/courtEquipment/selectCourtequipment", {uid: uid}, function (result) {
        if (result.data) {
            $("#_uid").val(uid);
            $("._court").val(result.data.court_id);
            $("#_courtRoom").val(result.data.courtroomid);
            $("#_devno").val(result.data.devno);
            $("#_devname").val(result.data.devname);
            $("#_devtype").val(result.data.devtype);
            $("#_devpos").val(result.data.devpos);
            $("#_devstatus").val(result.data.devstatus);
            $("#_devmemo").val(result.data.devmemo);
            $("#_editEqInfo").modal("show");
        }
    }, 'json')
}
function deleteCourtequipment(uid) {
    $('#_deleteEqInfo').find("input").val(uid);
    $('#_deleteEqInfo').find(".modal-body").html("删除编号《  " + uid + "  》的数据吗？");
    $('#_deleteEqInfo').modal();
}
function deleteEqInfoModal() {
    var val = $('#_deleteEqInfo').find("input").val();
    $.ajax({
        url: r.base_path + "sys/courtEquipment/deleteCourtEquipmentById",
        type: "post",
        data: {
            uid: val
        },
        dataType: "json",
        success: function (result) {
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.msg("操作成功！");
            });
            getSumNumberForCourtEquipment();
            $('#_deleteEqInfo').modal('hide');
        },
        error: function () {
        }
    });
}

function addCourtEquipment() {

    var court_id = $("#_court").val();
    var courtroomid = $("#_courtRoom").val();
    var devno = $("#_devno").val();
    var devname = $("#_devname").val();
    var devtype = $("#_devtype").val();
    var devpos = $("#_devpos").val();
    var devstatus = $("#_devstatus").val();
    var devmemo = $("#_devmemo").val();
    var _uid = $("#_uid").val();
    if (courtroomid == null || courtroomid == "") {
        alert("法庭名称不能为空");
        return;
    }
    if (_uid) {
        $.post(r.base_path + "sys/courtEquipment/updateCourtEquipment", {
            uid: _uid,
            court_id: court_id,
            courtroomid: courtroomid,
            devno: devno,
            devname: devname,
            devtype: devtype,
            devpos: devpos,
            devstatus: devstatus,
            devmemo: devmemo
        }, function (result) {
            if (result) {
                layui.use('layer', function () {
                    var layer = layui.layer;
                    layer.msg(result.msg);
                });
                getSumNumberForCourtEquipment();
                $("#_editEqInfo").modal("hide");
            }
        }, 'json');
    } else {
        $.ajax({
            url: r.base_path + "sys/courtEquipment/insertCourtEquipment",
            type: "post",
            dataType: "json",
            data: {
                court_id: court_id,
                courtroomid: courtroomid,
                devno: devno,
                devname: devname,
                devtype: devtype,
                devpos: devpos,
                devstatus: devstatus,
                devmemo: devmemo
            },
            success: function (result) {
                if (result.data != 0) {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg("添加成功！");
                    });
                    getSumNumberForCourtEquipment();
                    $("#_editEqInfo").modal("hide");
                }
            },
            error: function () {
            }
        });
    }
}

function pageEq(now, totalPages, callback) {
    base.pagination('#_page_eq', {
        currentPage: now,
        totalPages: totalPages,
        onPageClicked: function (page) {
            callback(page);
        }
    });
}